/**
 * 员工树测试数据
 * @returns {Promise}
 */
function exampleTreeEmployees () {
  return new Promise(function (resolve, reject) {
    http.request(api.exampleTreeEmployees).then(res => {
      if (res.code === 0) {
        resolve(res)
      } else {
        reject(res)
      }
    })
  })
}

function examplePrintMaterialList (data) {
  return new Promise(function (resolve, reject) {
    http.request(api.examplePrintMaterialList, data, 'GET').then(res => {
      if (res.code === 0) {
        resolve(res)
      } else {
        reject(res)
      }
    })
  })
}

// 测试小白接口
function getSysMenuList () {
  return new Promise(function (resolve, reject) {
    http.request(api.sysMenuList).then(res => {
      if (res.data.err_code === 0) {
        let data = res.data.list
        let tempArray = []
        data.forEach((element, index, array) => {
          tempArray[index] = {
            'menuId': parseInt(element.menuId),
            'parentId': parseInt(element.parentId),
            'parentName': element.parentName,
            'name': element.menu_name,
            'url': element.url,
            'perms': element.perms,
            'type': parseInt(element.menu_type),
            'icon': element.icon,
            'orderNum': element.orderNum,
            'open': element.menu_open,
            'list': null
          }
        })
        res.data.data = tempArray
        resolve(res.data)
      } else {
        reject(res.data)
      }
    })
  })
}

function getSysMenuInfo (menuId) {
  return new Promise(function (resolve, reject) {
    http.request(api.sysMenuInfo + '&where=[["menuId","=","' + menuId + '"]]').then(res => {
      if (res.data.err_code === 0) {
        resolve(res.data)
      } else {
        reject(res.data)
      }
    })
  })
}

function saveSysmenuItem (data) {
  return new Promise(function (resolve, reject) {
    let postData = {
      model_name: 'sys_menu',
      app_key: '648E0EAC0156CA958210E3300581731C',
      data: data
    }
    http.request(api.sysMenuSave, postData, 'POST').then(res => {
      if (res.data.err_code === 0) {
        resolve(res.data)
      } else {
        reject(res.data)
      }
    })
  })
}

function updateSysMenuItem (id, data) {
  return new Promise(function (resolve, reject) {
    http.request(api.sysMenuUpdate + 'where=[["menu_id","=","' + id + '"]]&data=' + data).then(res => {
      if (res.data.err_code === 0) {
        resolve(res.data)
      } else {
        reject(res.data)
      }
    })
  })
}

function getSysMenuMaxId () {
  return new Promise(function (resolve, reject) {
    http.request(api.sysMenuMaxId).then(res => {
      if (res.data.err_code === 0) {
        resolve(res.data)
      } else {
        reject(res.data)
      }
    })
  })
}


import http from '@/utils/httpRequest'
import api from '@/service/api/system'

/**
 * 获取全部部门，用于部门选择选择框
 */
function getDepartmentOptions () {
  return new Promise(function (resolve, reject) {
    http.request(api.exampleDepartmentsList).then(res => {
      if (res.code === 0) {
        resolve(res)
      } else {
        reject(res)
      }
    })
  })
}

/**
 * 获取角色信息，用于复选框
 */
function getRoleOption () {
  return new Promise(function (resolve, reject) {
    http.request(api.exampleRolesList).then(res => {
      if (res.code === 0) {
        resolve(res)
      } else {
        reject(res)
      }
    })
  })
}

/**
 * 获取课程信息，用于穿梭框
 */
function getCourseOptionList () {
  return new Promise(function (resolve, reject) {
    http.request(api.exampleCoursesList).then(res => {
      if (res.code === 0) {
        resolve(res)
      } else {
        reject(res)
      }
    })
  })
}

/**
 * 根据ID获取Grid行的详细信息
 * @param {行的id} value
 */
function getExampleGridInfo (value) {
  return new Promise(function (resolve, reject) {
    http.request(api.exampleGridInfo + '?id=' + value).then(res => {
      if (res.code === 0) {
        resolve(res)
      } else {
        reject(res)
      }
    })
  })
}

/**
 * 获取全部菜单信息
 */
function getExampleMenuList () {
  return new Promise(function (resolve, reject) {
    http.request(api.sysMenuList).then(res => {
      if (parseInt(res.status) === 200) {
        resolve(res)
      } else {
        reject(res)
      }
    })
  })
}



export default {

  getExampleMenuList,
  getDepartmentOptions,
  getRoleOption,
  getCourseOptionList,
  getExampleGridInfo
}
